package org.idea.qiyu.framework.canal.rocketmq.handler;

import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.message.MessageExt;
import org.idea.qiyu.framework.canal.rocketmq.config.MQProducerConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 监听user表相关的mq消息
 *
 * @Author linhao
 * @Date created in 5:17 下午 2021/6/22
 */
@Component
public class UserMqHandler implements MessageListenerConcurrently {

    private static final Logger LOGGER = LoggerFactory.getLogger(UserMqHandler.class);

    @Override
    public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
        if (CollectionUtils.isEmpty(list)) {
            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        }
        //对于消息的扩展内容，可以从中获取到更多信息
        for (MessageExt messageExt : list) {
            handleMsg(messageExt);
        }
        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
    }

    public void handleMsg(MessageExt messageExt) {
        LOGGER.info("msg is : {}", messageExt);
        byte[] bytes = messageExt.getBody();
    }

}
